package com.example.rabbitmq;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean
    public MessageConverter integrationEventMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
        return new RabbitAdmin(connectionFactory);
    }

//    //1. 交换机
//    @Bean("directExchange")
//    public DirectExchange directExchange() {
//        return new DirectExchange(RabbitMQConstants.DIRECT_EXCHANGE_NAME, true, false);
//    }
//
//    //2. 队列
//    @Bean("judgeDirectQueue")
//    public Queue judgeDirectQueue() {
//        return new Queue(RabbitMQConstants.DIRECT_JUDGE_QUEUE_NAME, true);
//    }
//
//    //3. 队列和交换机绑定 Binding
//    @Bean
//    public Binding binding(@Qualifier("directExchange") Exchange exchange, @Qualifier("judgeDirectQueue") Queue queue) {
//        return BindingBuilder.bind(queue).to(exchange).with(RabbitMQConstants.DIRECT_JUDGE_ROUTE_KEY).noargs();
//    }
}
